import { getXzqh } from '@/api/service/xzqhApi.js'

export function useXzqh() {
  const router = useRouter()
  const { userStore } = useStore()
  const orgcode = userStore.user.orgcode
  const xzqhData = ref([])

  // 获取行政区划
  const getXzqhFn = () => {
    getXzqh({
      orgcode,
    }).then((res) => {
      xzqhData.value = res.result[0].nodes || res.result[0]
    })
  }

  // 点击村，设置村
  const setOrgnow = (cun) => {
    userStore.orgnow.orgnowcode = cun.orgcode
    userStore.orgnow.orgnowname = cun.text
    router.replace('/')
  }

  return {
    getXzqhFn,
    xzqhData,
    setOrgnow,
  }
}
